package com.xyh.jdkDemo;


import com.sun.scenario.effect.impl.hw.ShaderSource;
import com.sun.xml.internal.xsom.impl.EmptyImpl;
import com.xyh.jdkDemo.vo.BeanOopDemo;
import com.xyh.jdkDemo.vo.Cat;

import javax.sound.midi.Soundbank;
import java.awt.*;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Calendar;

import static java.lang.Math.E;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;

/**
 * @version v1.0
 * @类描述：
 * @项目名称：
 * @包名： JavaCancheDemo
 * @类名称：Demo
 * @创建人：YIHANG.XU
 * @创建时间：2020/5/1811:14 上午
 * @修改人：YIHANG.XU
 * @修改时间：2020/5/1811:14 上午
 * @修改备注：
 * @Copyright
 */

@myAction({"ddd", "ddd"})
public class ActionDemo extends DemoFather {
    private String name = "张三";
    private String sex = "男";
    public String lll = "dd";

    @myAction({"ccc"})
    public void test1() {


    }

}

class DemoFather {
    String name = "2";
}

@Retention(RetentionPolicy.RUNTIME)
@Target(value = {TYPE, METHOD})
@Inherited
@interface myAction {
    String[] value();

}

/**
 * 注解反射测试类
 */
class ClassTest {
    public static void main(String[] args) {
        try {
            Class aClass = Class.forName("JavaCancheDemo.Demo");
            Class demoClass = ActionDemo.class;

            Method[] methods1 = demoClass.getMethods();
            System.out.println(methods1[0].getName());
            Method[] methods = aClass.getMethods();
            System.out.println(methods[0].getName());
            Class superclass = demoClass.getSuperclass();
            String name = superclass.getName();
            System.out.println(name);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}

/**
 * 类加载测试类
 */
class Test2 {
    public static void main(String[] args) {
        //系统类加载器
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
        System.out.println(systemClassLoader);
        //系统类加载器父类加载器 拓展加载器
        ClassLoader parent = systemClassLoader.getParent();
        System.out.println(parent);
        //拓展加载器父类 根加载器 但是java 获取不到
        ClassLoader parent1 = parent.getParent();
        System.out.println(parent1);
        //自定义
        ClassLoader classLoader = ActionDemo.class.getClassLoader();
        System.out.println("自定义方法类加载器" + classLoader);
        //官方
        ClassLoader classLoader1 = Object.class.getClassLoader();
        System.out.println(classLoader1);
        //获取系统类加载路径
        System.out.println(System.getProperty("java.class.path"));
        //什么是双亲委派机制，就是当自己出的包在拓展加载器或是在根加载器中存在就会直接使用根加载中的包 为了安全性


    }
}

/**
 * 反射是测试类
 */
class Test3 {
    public static void main(String[] args) {
        System.out.println(ActionDemo.class.getName());
        Field[] fields = ActionDemo.class.getFields();
        for (int i = 0; i < fields.length; i++) {
            System.out.println(fields[i]);
        }
        Field[] declaredFields = ActionDemo.class.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            System.out.println(declaredField.getName());
        }
    }

}

class Tset4 {
    /**
     * 对象测试类
     *
     * @param args
     */
    public static void main(String[] args) {
        BeanOopDemo beanOopDemo = null;
        System.out.println("开始");
        beanOopDemo = new BeanOopDemo();
        Cat cat = new Cat("小贝", "20", "母猫");
        String name = cat.getName();
        System.out.println(name);
        Cat cat1 = new Cat();
        Cat cat2 = new Cat();
        System.out.println(cat1 == cat2);
        System.out.println(cat1.equals(cat2));


    }
}
